﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Drawing;
using System.Diagnostics;

namespace Gw2ToolNewSystem
{
    public class tqToolTip
    {
        public Dictionary<Control, Content> ToolTipList = new Dictionary<Control, Content>();
        public toolTip1 form;
        public Timer timer;
        public bool ItsOk = false;
        public long CurrentTick;
        public Control CurrentControl;
        public tqToolTip()
        {
            form = new toolTip1();
        }

        public void SetToolTip(Control ctn, Content con)
        {
            if (ToolTipList.ContainsKey(ctn))
            {
                ToolTipList[ctn] = con;
                
            }
            else
            {
                ToolTipList.Add(ctn, con);

            }
            //ctn.MouseMove += new MouseEventHandler(ctn_MouseMove);
            ctn.MouseLeave += new EventHandler(ctn_MouseLeave);
            ctn.MouseEnter += new EventHandler(ctn_MouseEnter);
            ctn.Click += new EventHandler(ctn_Click);
            
        }

        void ctn_Click(object sender, EventArgs e)
        {
            ((Control)sender).Focus();
        }

        void ctn_MouseEnter(object sender, EventArgs e)
        {
            try
            {
                if (ToolTipList.ContainsKey((Control)sender) && !ItsOk)
                {
                    Content con = ToolTipList[(Control)sender];
                    if (!con.Opened)
                    {
                        con.Opened = true;
                        CurrentControl = (Control)sender;
                        CurrentTick = DateTime.Now.Ticks;
                        ItsOk = true;
                        form.ChangeContent(con);
                    }
                }
                else
                {

                }
            }
            catch (Exception ex)
            {
                System.Windows.Forms.MessageBox.Show(ex.ToString());
            }
        }

        void ctn_MouseMove(object sender, MouseEventArgs e)
        {

        }

        void ctn_MouseLeave(object sender, EventArgs e)
        {
            try
            {
                if (ToolTipList.ContainsKey((Control)sender) && ItsOk)
                {
                    ClearControl((Control)sender);
                }
                else
                {

                }
            }
            catch (Exception ex)
            {
                System.Windows.Forms.MessageBox.Show(ex.ToString());
            }
        }
        public void ClearControl(Control sender)
        {
            if (DateTime.Now.Ticks - CurrentTick > 20000)
            {
                Content con = ToolTipList[sender];
                if (con.Opened)
                {
                    con.Opened = false;
                    ItsOk = false;
                    form.Clear();
                    form.Hide();
                }
            }

        }
        void timer_Tick(object sender, EventArgs e)
        {
        }
    }
    public class Content
    {
        public string Text, Title, CoolDown,SkillPoint,Initiative;
        public Image Picture;
        public bool Opened = false;
        public Dictionary<Image, string> MiniInfos = new Dictionary<Image, string>();
        public Content(string title, string text)
        {
            Title = title;
            Text = text;
        }
        public Content(string title, string text, Image img, string cooldown, string skilpoint, string init)
        {
            Initiative = init;
            SkillPoint = skilpoint;
            CoolDown = cooldown;
            Title = title;
            Text = text;
            Picture = img;
        }
        public Content(string title, string text, Image img, string cooldown,string skilpoint)
        {
            Initiative = "0";
            SkillPoint = skilpoint;
            CoolDown = cooldown;
            Title = title;
            Text = text;
            Picture = img;
        }
        public Content(string title, string text, Image img, string cooldown)
        {
            Initiative = "0";
            SkillPoint = "0";
            CoolDown = cooldown;
            Title = title;
            Text = text;
            Picture = img;
        }
        public Content(string title, string text, Image img)
        {
            Initiative = "0";
            SkillPoint = "0";
            CoolDown = "0";
            Title = title;
            Text = text;
            Picture = img;
        }
       

        public void MiniInformation(string text, Image img)
        {
            MiniInfos.Add(img, text);
        }
    }
}
